﻿using System;
using Myotragus.Data.Util;
using Myotragus.Store.Model.DefaultRepositories;
using Myotragus.Store.Model.Domain;
using Myotragus.Store.Model.Helpers;
using NHibernate.Cfg;
using NHibernate.Criterion;
using NUnit.Framework;

namespace Myotragus.Store.Model.Tests
{
  [TestFixture]
  public class CategoryProductsFixture
  {
    [SetUp]
    public void SetUp()
    {
      //FixtureHelper.InitializeServices(ServicesImplementation.FromAssemblyContaining<IProduct>());
      //var entitites = new[] { typeof(ICategory), typeof(IProduct) };
      //FixtureHelper.InitializeEntities(entitites);
      //FixtureHelper.InitializeSession(entitites);
      //var resolver = FixtureHelper.Container.Resolve<IResolutionHbmGenerator>();
      //var hbm = resolver.Generate(Mappings.CategoryProducts);
      //FixtureHelper.AddMappings(hbm);
      //FixtureHelper.Container.Resolve<IEntitiesContainer>();

      Core.Register(new Configuration(), new[] { typeof(ICategory), typeof(IProduct) }, 
        new[] { Mappings.CategoryProducts });
    }

    [Test]
    public void TestRead()
    {
      var repo = Core.Container.Resolve<ICategoryRepository>();
      foreach (var p in repo.GetProductsIn(1, 99, Order.Desc("Name")))
        FixtureHelper.Print(p.Name);
    }

    [Test]
    public void Problems()
    {
      var categories = FixtureHelper.Container.Resolve<ICategoryRepository>();
      var products = FixtureHelper.Container.Resolve<IProductRepository>();

      var alias= LocalizableCriteriaHelper.ResolveAlias(products);
      Console.WriteLine(alias);

      var desc = LocalizableCriteriaHelper.ResolveEntityDescriptor(products);
      Console.WriteLine(desc);
    }
  }
}